package com.xlg.file.center.handler;

import com.xlg.file.center.utils.FileType;

import java.util.HashMap;
import java.util.Map;

/**
 * @author: 18310740596@163.com
 * @date: 2023-07-15 00:09:21
 * @version: v1.0
 * @describe: class responsibility
 */
public class FileHandlerFactory {

    final static Map<FileType, IFileHandler> HANDLER_MAP = new HashMap<>();

    static {
        HANDLER_MAP.put(FileType.CSV, new CsvFileHandler());
        HANDLER_MAP.put(FileType.XSL, new ExcelFileHandler());
        HANDLER_MAP.put(FileType.XSLX, new ExcelFileHandler());
    }


    public static IFileHandler instance(FileType fileType) throws Exception {
        if (fileType == null) {
            throw new Exception("文件类型不能为空!!!");
        }
        if (!HANDLER_MAP.containsKey(fileType)) {
            throw new Exception("暂不支持该文件类型生成!!!");
        }
        return HANDLER_MAP.get(fileType);
    }

}
